package edu.zju.jzs.firstsort.process;

import edu.zju.jzs.firstsort.entity.FlowBean;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * Created by 11544 on 2017/10/13.
 */
public class FlowCountReducer extends Reducer<Text,FlowBean,Text,FlowBean> {
    @Override
    protected void reduce(Text key, Iterable<FlowBean> values, Context context) throws IOException, InterruptedException {
//        super.reduce(key, values, context);

        FlowBean bean=new FlowBean();
        bean.setSumflow(0);
        bean.setDownflow(0);
        bean.setUpflow(0);
        for (FlowBean value:values)
        {
            bean.setSumflow(bean.getSumflow()+value.getSumflow());
            bean.setUpflow(bean.getUpflow()+value.getUpflow());
            bean.setDownflow(bean.getDownflow()+value.getDownflow());
        }
        context.write(new Text(key),bean);
//    context.write(phonenumber,key);

    }
}
